<template>
  <el-form-item :prop="form.model" :label="form.label">
    <el-radio-group v-if="form.type === 'radio'" v-model="inputValue">
      <el-radio v-for="(item, index) in form.radio" :key="index" :label="item.value">{{item.label}}</el-radio>
    </el-radio-group>
    <template v-else-if="form.type === 'select'">
    <el-select v-model="inputValue" :placeholder="form.label">
      <el-option v-for="(item, index) in form.select" :key="index" :value="item.value" :label="item.label"></el-option>
    </el-select>
    </template>
    <template v-else-if="form.type === 'upload_1'">
      <el-upload
        class="upload-demo"
        ref="upload"
        action
        :file-list="fileList"
        :on-change="handleChange"
        :on-remove="handleRemove"
        :auto-upload="false">
        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
        <div slot="tip" class="el-upload__tip">{{form.tip}}</div>
      </el-upload>
    </template>
    <el-input v-else :type="form.type" v-model="inputValue" :placeholder="form.label"></el-input>
  </el-form-item>
</template>

<script>
export default {
  name: 'ZForm',
  props: ['form', 'value'],
  watch: {
    inputValue(value, oldValue) {
      this.$emit('input', value)
    },
    value(value) {
      this.inputValue = value
    }
  },
  data() {
    return {
      inputValue: '',
      fileList: []
    }
  },
  methods: {
    handleChange(file, fileList) {
      this.fileList = fileList.slice(-1)
      this.$emit('input', file.raw)
    },
    handleRemove(file, fileList) {
      console.log(fileList)
      this.$emit('input', null)
    }
  },
  created() {
    this.inputValue = this.value
  }
}
</script>

<style scoped>

</style>
